<?php
class User {
	public static function update($post_data)
	{
		if (isset($post_data[Protocol::ID])) {
			// On Update
			$data[Protocol::ID] 		= $post_data[Protocol::ID];
			$data[Protocol::IS_MODEL]	= $post_data[Protocol::IS_MODEL];
			$data[Protocol::VIEWS]		= $post_data[Protocol::VIEWS];
			$data[Protocol::LIKES]		= $post_data[Protocol::LIKES];
		}
		else {
			// On Create
			$data[Protocol::CREATED_TIME] = time();
		}
		
		$data[Protocol::EMAIL]			= $post_data[Protocol::EMAIL];
		$data[Protocol::PASSWORD]		= $post_data[Protocol::PASSWORD];
		$data[Protocol::NAME]			= $post_data[Protocol::NAME];
		$data[Protocol::DESCRIPTION]	= $post_data[Protocol::DESCRIPTION];
		$data[Protocol::MODIFIED_TIME]	= time();
		
		return DBConnector::update(
			Protocol::USER, $data
		);
	}
	
	public static function get_list($start = FALSE, $end = FALSE, $keyword = FALSE, $order = FALSE)
	{
		$fields = array(
			Protocol::ID, Protocol::NAME, Protocol::IS_MODEL, Protocol::VIEWS, Protocol::LIKES
		);
		$search_fields = array(Protocol::NAME);
		return DBConnector::get_list(Protocol::USER, $start, $end, $search_fields, $keyword, $order, $fields);
	}
	
	public static function get($value, $key = FALSE)
	{
		if ($key === FALSE) $key = Protocol::ID;
		return DBConnector::get(Protocol::USER, $key, $value);
	}
	
	public static function delete($id_list)
	{
		return DBConnector::delete(Protocol::USER, $id_list);
	}
}
